/*
 * Copyright (C) 2006  Antonie Struyk
 *
 * This file is part of MusicFlashCards.
 *
 *    Freetar Hero is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    MusicFlashCards is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with MusicFlashCards; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package com.antonstruyk.musicflashcards;

/**
 *
 * @author  Anton
 */
public class CardGUI extends javax.swing.JFrame {
    
    private Note currentNote = null;
    private RandomNoteGenerator randomNoteGenerator;
    private int correct = 0;
    private int incorrect = 0;
    private Timer timer;
    
    /** Creates new form CardGUI */
    public CardGUI() {
        randomNoteGenerator = new RandomNoteGenerator(Note.ALL_NOTES);
        timer = new Timer();
        
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        allowedNotesButtonGroup = new javax.swing.ButtonGroup();
        noteSelectionPanel = new javax.swing.JPanel();
        aButton = new javax.swing.JButton();
        bButton = new javax.swing.JButton();
        cButton = new javax.swing.JButton();
        dButton = new javax.swing.JButton();
        eButton = new javax.swing.JButton();
        fButton = new javax.swing.JButton();
        gButton = new javax.swing.JButton();
        noteDisplayAreaPanel = new javax.swing.JPanel();
        noteDisplayPanel = new com.antonstruyk.musicflashcards.NoteDisplayPanel();
        controlPanel = new javax.swing.JPanel();
        nextFlashCardButton = new javax.swing.JButton();
        statusBarPanel = new javax.swing.JPanel();
        messageAreaLabel = new javax.swing.JLabel();
        scorePanel = new javax.swing.JPanel();
        correctLabel = new javax.swing.JLabel();
        correctAreaLabel = new javax.swing.JLabel();
        incorrectLabel = new javax.swing.JLabel();
        incorrectAreaLabel = new javax.swing.JLabel();
        menuBar1 = new javax.swing.JMenuBar();
        fileMenu1 = new javax.swing.JMenu();
        restartMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        optionsMenu = new javax.swing.JMenu();
        allowSharpsAndFlatsMenuItem = new javax.swing.JCheckBoxMenuItem();
        showNoteNamesMenuItem = new javax.swing.JCheckBoxMenuItem();
        allowedNotesMenu = new javax.swing.JMenu();
        allNotesMenuItem = new javax.swing.JCheckBoxMenuItem();
        cMajorRightHandMenuItem = new javax.swing.JCheckBoxMenuItem();
        cMajorLeftHandMenuItem = new javax.swing.JCheckBoxMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Music Note Flash Cards");
        setLocationByPlatform(true);
        noteSelectionPanel.setLayout(new java.awt.GridLayout(1, 7));

        noteSelectionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Note Selection Area"));
        aButton.setText("A");
        aButton.setFocusable(false);
        aButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aButtonActionPerformed(evt);
            }
        });

        noteSelectionPanel.add(aButton);

        bButton.setText("B");
        bButton.setFocusable(false);
        bButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bButtonActionPerformed(evt);
            }
        });

        noteSelectionPanel.add(bButton);

        cButton.setText("C");
        cButton.setFocusable(false);
        cButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cButtonActionPerformed(evt);
            }
        });

        noteSelectionPanel.add(cButton);

        dButton.setText("D");
        dButton.setFocusable(false);
        dButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dButtonActionPerformed(evt);
            }
        });

        noteSelectionPanel.add(dButton);

        eButton.setText("E");
        eButton.setFocusable(false);
        eButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eButtonActionPerformed(evt);
            }
        });

        noteSelectionPanel.add(eButton);

        fButton.setText("F");
        fButton.setFocusable(false);
        fButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fButtonActionPerformed(evt);
            }
        });

        noteSelectionPanel.add(fButton);

        gButton.setText("G");
        gButton.setFocusable(false);
        gButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gButtonActionPerformed(evt);
            }
        });

        noteSelectionPanel.add(gButton);

        noteDisplayAreaPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Note Display Area"));
        org.jdesktop.layout.GroupLayout noteDisplayPanelLayout = new org.jdesktop.layout.GroupLayout(noteDisplayPanel);
        noteDisplayPanel.setLayout(noteDisplayPanelLayout);
        noteDisplayPanelLayout.setHorizontalGroup(
            noteDisplayPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 253, Short.MAX_VALUE)
        );
        noteDisplayPanelLayout.setVerticalGroup(
            noteDisplayPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 193, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout noteDisplayAreaPanelLayout = new org.jdesktop.layout.GroupLayout(noteDisplayAreaPanel);
        noteDisplayAreaPanel.setLayout(noteDisplayAreaPanelLayout);
        noteDisplayAreaPanelLayout.setHorizontalGroup(
            noteDisplayAreaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, noteDisplayAreaPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(noteDisplayPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        noteDisplayAreaPanelLayout.setVerticalGroup(
            noteDisplayAreaPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(noteDisplayAreaPanelLayout.createSequentialGroup()
                .add(noteDisplayPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        controlPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Controls (TEMP)"));
        nextFlashCardButton.setText("NEXT FLASH CARD");
        nextFlashCardButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextFlashCardButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout controlPanelLayout = new org.jdesktop.layout.GroupLayout(controlPanel);
        controlPanel.setLayout(controlPanelLayout);
        controlPanelLayout.setHorizontalGroup(
            controlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(controlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(nextFlashCardButton)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        controlPanelLayout.setVerticalGroup(
            controlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(controlPanelLayout.createSequentialGroup()
                .add(nextFlashCardButton)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        statusBarPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        messageAreaLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        messageAreaLabel.setText("      ");

        org.jdesktop.layout.GroupLayout statusBarPanelLayout = new org.jdesktop.layout.GroupLayout(statusBarPanel);
        statusBarPanel.setLayout(statusBarPanelLayout);
        statusBarPanelLayout.setHorizontalGroup(
            statusBarPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusBarPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(messageAreaLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
                .addContainerGap())
        );
        statusBarPanelLayout.setVerticalGroup(
            statusBarPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, messageAreaLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        scorePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Score"));
        correctLabel.setText("Correct:");

        correctAreaLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        correctAreaLabel.setText("0");

        incorrectLabel.setText("Incorrect:");

        incorrectAreaLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        incorrectAreaLabel.setText("0");

        org.jdesktop.layout.GroupLayout scorePanelLayout = new org.jdesktop.layout.GroupLayout(scorePanel);
        scorePanel.setLayout(scorePanelLayout);
        scorePanelLayout.setHorizontalGroup(
            scorePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(scorePanelLayout.createSequentialGroup()
                .add(scorePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(incorrectLabel)
                    .add(correctLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(scorePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(correctAreaLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
                    .add(incorrectAreaLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE))
                .addContainerGap())
        );
        scorePanelLayout.setVerticalGroup(
            scorePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(scorePanelLayout.createSequentialGroup()
                .add(scorePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(correctLabel)
                    .add(correctAreaLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(scorePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(incorrectLabel)
                    .add(incorrectAreaLabel)))
        );

        fileMenu1.setMnemonic('F');
        fileMenu1.setText("File");
        restartMenuItem.setMnemonic('R');
        restartMenuItem.setText("Reset Game");
        restartMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                restartMenuItemActionPerformed(evt);
            }
        });

        fileMenu1.add(restartMenuItem);

        exitMenuItem.setMnemonic('X');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });

        fileMenu1.add(exitMenuItem);

        menuBar1.add(fileMenu1);

        optionsMenu.setMnemonic('O');
        optionsMenu.setText("Options");
        allowSharpsAndFlatsMenuItem.setText("Allow Sharps And Flats");
        allowSharpsAndFlatsMenuItem.setEnabled(false);
        optionsMenu.add(allowSharpsAndFlatsMenuItem);

        showNoteNamesMenuItem.setText("Show Note Names");
        showNoteNamesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showNoteNamesMenuItemActionPerformed(evt);
            }
        });

        optionsMenu.add(showNoteNamesMenuItem);

        allowedNotesMenu.setText("Allowed Notes");
        allNotesMenuItem.setSelected(true);
        allNotesMenuItem.setText("All Notes");
        allNotesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                allNotesMenuItemActionPerformed(evt);
            }
        });

        allowedNotesMenu.add(allNotesMenuItem);

        cMajorRightHandMenuItem.setText("Right Hand in C Major");
        cMajorRightHandMenuItem.setEnabled(false);
        cMajorRightHandMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cMajorRightHandMenuItemActionPerformed(evt);
            }
        });

        allowedNotesMenu.add(cMajorRightHandMenuItem);

        cMajorLeftHandMenuItem.setText("Left Hand in C Major");
        cMajorLeftHandMenuItem.setEnabled(false);
        cMajorLeftHandMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cMajorLeftHandMenuItemActionPerformed(evt);
            }
        });

        allowedNotesMenu.add(cMajorLeftHandMenuItem);

        optionsMenu.add(allowedNotesMenu);

        menuBar1.add(optionsMenu);

        helpMenu.setMnemonic('H');
        helpMenu.setText("Help");
        aboutMenuItem.setMnemonic('A');
        aboutMenuItem.setText("About");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });

        helpMenu.add(aboutMenuItem);

        menuBar1.add(helpMenu);

        setJMenuBar(menuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusBarPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(controlPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 14, Short.MAX_VALUE)
                        .add(scorePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, noteSelectionPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(noteDisplayAreaPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(noteDisplayAreaPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(noteSelectionPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(controlPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(scorePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(statusBarPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cMajorLeftHandMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cMajorLeftHandMenuItemActionPerformed
        if(cMajorLeftHandMenuItem.isSelected()){
            randomNoteGenerator.addNotes(Note.C_MAJOR_LEFT_HAND);
        }else{
            randomNoteGenerator.removeNotes(Note.C_MAJOR_LEFT_HAND);
        }
    }//GEN-LAST:event_cMajorLeftHandMenuItemActionPerformed

    private void cMajorRightHandMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cMajorRightHandMenuItemActionPerformed
        if(cMajorRightHandMenuItem.isSelected()){
            randomNoteGenerator.addNotes(Note.C_MAJOR_RIGHT_HAND);
        }else{
            randomNoteGenerator.removeNotes(Note.C_MAJOR_RIGHT_HAND);
        }
    }//GEN-LAST:event_cMajorRightHandMenuItemActionPerformed

    private void allNotesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allNotesMenuItemActionPerformed
        if(allNotesMenuItem.isSelected()){
            //Disable the other buttons
            cMajorLeftHandMenuItem.setEnabled(false);
            cMajorRightHandMenuItem.setEnabled(false);
            
            //Add all the notes
            randomNoteGenerator.addNotes(Note.ALL_NOTES);
        }else{
            //Remove all notes
            randomNoteGenerator.removeNotes(Note.ALL_NOTES);
            
            //Enable the other buttons
            cMajorLeftHandMenuItem.setEnabled(true);
            cMajorRightHandMenuItem.setEnabled(true);
            
            //Add the notes for the other buttons that are selected
            cMajorRightHandMenuItemActionPerformed(null);
            cMajorLeftHandMenuItemActionPerformed(null);
        }
    }//GEN-LAST:event_allNotesMenuItemActionPerformed

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        javax.swing.JOptionPane.showMessageDialog(this,
                "Note Flash Cards v0.1\n\n" +
                "By: Anton Struyk\n\n" +
                "Web: http://www.antonstruyk.com/ \n" +
                "Email: anton@antonstruyk.com");
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void gButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gButtonActionPerformed
        checkNoteNameEquals("G");
    }//GEN-LAST:event_gButtonActionPerformed

    private void fButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fButtonActionPerformed
        checkNoteNameEquals("F");
    }//GEN-LAST:event_fButtonActionPerformed

    private void eButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eButtonActionPerformed
        checkNoteNameEquals("E");
    }//GEN-LAST:event_eButtonActionPerformed

    private void dButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dButtonActionPerformed
        checkNoteNameEquals("D");
    }//GEN-LAST:event_dButtonActionPerformed

    private void cButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cButtonActionPerformed
        checkNoteNameEquals("C");
    }//GEN-LAST:event_cButtonActionPerformed

    private void bButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bButtonActionPerformed
        checkNoteNameEquals("B");
    }//GEN-LAST:event_bButtonActionPerformed

    private void aButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aButtonActionPerformed
        checkNoteNameEquals("A");
    }//GEN-LAST:event_aButtonActionPerformed

    private void restartMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restartMenuItemActionPerformed
        incorrect = 0;
        correct = 0;
        correctAreaLabel.setForeground(java.awt.Color.BLACK);
        incorrectAreaLabel.setForeground(java.awt.Color.BLACK);
        correctAreaLabel.setText("0");
        incorrectAreaLabel.setText("0");
        currentNote = null;
        noteDisplayPanel.clearNotes();
        timer.stop();
    }//GEN-LAST:event_restartMenuItemActionPerformed

    private void showNoteNamesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showNoteNamesMenuItemActionPerformed
        noteDisplayPanel.showNoteNames(showNoteNamesMenuItem.isSelected());
    }//GEN-LAST:event_showNoteNamesMenuItemActionPerformed

    private void nextFlashCardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextFlashCardButtonActionPerformed
        if(currentNote != null){
            noteDisplayPanel.removeNote(currentNote);
            incorrectNote();
        }
       
        generateNewNote();
    }//GEN-LAST:event_nextFlashCardButtonActionPerformed
    
    private void checkNoteNameEquals(String noteName){
        if(currentNote != null){
            if(currentNote.getName().equalsIgnoreCase(noteName)){
                correctNote();
            }else{
                incorrectNote();
            }
            generateNewNote();
        }
    }
    
    private void generateNewNote(){
        currentNote = randomNoteGenerator.nextNote();
        noteDisplayPanel.clearNotes();
        noteDisplayPanel.addNote(currentNote);
        timer.start();
    }
    
    private void incorrectNote(){
        timer.stop();
        incorrect++;
        correctAreaLabel.setForeground(java.awt.Color.BLACK);
        incorrectAreaLabel.setForeground(java.awt.Color.RED);
        incorrectAreaLabel.setText(incorrect + "");
        messageAreaLabel.setForeground(java.awt.Color.RED);
        messageAreaLabel.setText("Incorrect! The note was '" + currentNote.getName() + "'. " + timer.getTimeInSeconds() + " seconds.");
    }
    
    private void correctNote(){
        timer.stop();
        correct++;
        correctAreaLabel.setForeground(java.awt.Color.GREEN);
        incorrectAreaLabel.setForeground(java.awt.Color.BLACK);
        correctAreaLabel.setText(correct + "");
        messageAreaLabel.setForeground(java.awt.Color.GREEN);
        messageAreaLabel.setText("Correct! in " + timer.getTimeInSeconds() + " seconds.");
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CardGUI().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aButton;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JCheckBoxMenuItem allNotesMenuItem;
    private javax.swing.JCheckBoxMenuItem allowSharpsAndFlatsMenuItem;
    private javax.swing.ButtonGroup allowedNotesButtonGroup;
    private javax.swing.JMenu allowedNotesMenu;
    private javax.swing.JButton bButton;
    private javax.swing.JButton cButton;
    private javax.swing.JCheckBoxMenuItem cMajorLeftHandMenuItem;
    private javax.swing.JCheckBoxMenuItem cMajorRightHandMenuItem;
    private javax.swing.JPanel controlPanel;
    private javax.swing.JLabel correctAreaLabel;
    private javax.swing.JLabel correctLabel;
    private javax.swing.JButton dButton;
    private javax.swing.JButton eButton;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JButton fButton;
    private javax.swing.JMenu fileMenu1;
    private javax.swing.JButton gButton;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLabel incorrectAreaLabel;
    private javax.swing.JLabel incorrectLabel;
    private javax.swing.JMenuBar menuBar1;
    private javax.swing.JLabel messageAreaLabel;
    private javax.swing.JButton nextFlashCardButton;
    private javax.swing.JPanel noteDisplayAreaPanel;
    private com.antonstruyk.musicflashcards.NoteDisplayPanel noteDisplayPanel;
    private javax.swing.JPanel noteSelectionPanel;
    private javax.swing.JMenu optionsMenu;
    private javax.swing.JMenuItem restartMenuItem;
    private javax.swing.JPanel scorePanel;
    private javax.swing.JCheckBoxMenuItem showNoteNamesMenuItem;
    private javax.swing.JPanel statusBarPanel;
    // End of variables declaration//GEN-END:variables
    
}
